package com.electron.power.octopus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.electron.power.model.mod.ModBodyMap;
import com.electron.power.model.mod.ModStr;
import com.electron.power.octopus.service.ModService;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("api/mod/modstr")
@Slf4j
public class ModController {

	@Autowired
	private ModService modeService;

//	@ApiOperation("新增数据二进制数据")
//	@PostMapping(value = "mod", produces = MediaType.APPLICATION_JSON_VALUE)
//	@ResponseBody
//	public Mono<ModBodyMap> addMod(@RequestBody Mod mod) {
//		log.info("controller 接收到的数据为{}", mod);
//		return modeService.addMod(mod).doOnError(System.out::println);
//	}

//	@GetMapping(value = "all", produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
//	@ResponseBody
//	public Flux<Mod> queryAll() {
//		return modeService.queryAll();
//	}

	@GetMapping(value = "allStr", produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
	@ResponseBody
	public Flux<ModStr> findAll() {
		return modeService.findAll();
	}

	@ApiOperation("新增字符串数据")
	@PostMapping(value = "add", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Mono<ModBodyMap> addModStr(@RequestBody ModStr mod) {
		log.info("webflux 接收到的数据为:{}", mod);
		return modeService.addModStr(mod);
	}
}
